﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using libCommonTools.Forms;
using libInventory.BUS;
using libInventory.FORMS;
using libDAL;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
using Telerik.WinControls.RichTextBox;
using Telerik.WinControls.RichTextBox.Model;
using libModClassVB.libModClassVB.Classes;
using libInventory.dbml;
namespace libInventory.FORMS
{
    public partial class frmGRN : Telerik.WinControls.UI.RadForm
    {

        private struct Declarations
        { 
        
        }

        private string strGRNNo = string.Empty;
        private clsInterfaceGRN _BUS;
        private clsInterfaceSalesTerm _BUSIFSalesTerm;
        private string strShipperCompanyID = string.Empty;
        private string strConsigneeCompanyID = string.Empty;
        private string strShipperCompanyName = string.Empty;
        private string strConsigneeCompanyName = string.Empty;
        private string strSalesTermSetupHeaderID = string.Empty;
        private string strPortID = string.Empty;
        private bool bolNew = false;
        private bool bolUpdate = false;
    
        private tfcargorec settfCargoRec;

        private clsInterfaceAdditionalServices AdditionalServices;
        private RadRibbonBarGroup rrbgGRN;

        public bool getset_Update
        {
            get
            {
                return this.bolUpdate;
            }
            set
            {
                this.bolUpdate = value;
            }
        }

        public bool getset_New
        {
            get
            {
                return this.bolNew;
            }
            set
            {
                this.bolNew = value;
            }
        }

        private string getset_PortID
        {
            get
            {
                return strPortID;
            }
            set
            {
                strPortID = value;
            }
        }

        private string getset_ConsigneeCompanyName
        {
            get
            {
                return strConsigneeCompanyName;
            }
            set
            {
                strConsigneeCompanyName = value;
            }
        }

        public void set_BarGroup(ref RadRibbonBarGroup rrbg)
        {
            rrbgGRN = rrbg;
            rrbgGRN.Items["rbeGRNAdditionalServices"].Enabled = false;  
        }

        private string getset_SalesTermSetupHeaderID
        {
            get
            {
                return this.strSalesTermSetupHeaderID;
            }
            set
            {
                this.strSalesTermSetupHeaderID = value;
            }
        }

        private string getset_ShipperCompanyName
        {
            get
            {
                return strShipperCompanyName;
            }
            set
            {
                strShipperCompanyName = value;
            }
        }

        private string getset_ShipperCompanyID
        {
            get
            {
                return strShipperCompanyID;
            }
            set
            {
                strShipperCompanyID = value;
            }
        }

        private string getset_ConsigneeCompanyID
        {
            get
            {
                return strConsigneeCompanyID;
            }
            set
            {
                strConsigneeCompanyID = value;
            }
        }

        public void set_ReloadGRNDetails(string strGRNNo)
        {
            try
            {
                getset_GRNNo = strGRNNo;
                _BUS.getset_GRNNo = getset_GRNNo;
                if (_BUS.set_GRNMain() == true)
                {
                    //sets and checks records for GRN General Measurement
                    if (_BUS.set_GeneralMeasurment() == true)
                    {
                        //sets and checks records for Shipper Measurement
                        if (_BUS.set_ShipperMeasurment() == true)
                        {
                            //sets and checks records for Shipper Invoice
                            if (_BUS.set_ShipperInvoice() == true)
                            {
                                if (_BUS.getset_GRNMainDetails.Length > 0)
                                {
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ReloadGRNDetails"); 
            }
        }


        public void set_setGRNDetails(string strGRNNo)
        {
            try
            {
                getset_GRNNo = strGRNNo;
                _BUS.getset_GRNNo = getset_GRNNo;

                //sets and checks records for GRN
                if (_BUS.set_GRNMain() == true)
                {
                    //sets and checks records for GRN General Measurement
                    if (_BUS.set_GeneralMeasurment() == true)
                    {
                        //sets and checks records for Shipper Measurement
                        if (_BUS.set_ShipperMeasurment() == true)
                        {
                            //sets and checks records for Shipper Invoice
                            if (_BUS.set_ShipperInvoice() == true)
                            {
                                if (_BUS.getset_GRNMainDetails.Length > 0)
                                {
                                    //the the IO for shipper
                                    set_ShipperDetailsAddressGRN(_BUS.getset_GRNMainDetails);
                                    //the the IO for consignee
                                    set_ConsigneeDetailsAddressGRN(_BUS.getset_GRNMainDetails);
                                    //set datagrid for General Measurement
                                    set_LodGenMeasurementGrid();
                                    //set datagrid for Shipper Measurement
                                    set_LoadShipperMeasurement();
                                    //set datagrid for Shipper Invoice
                                    set_LoadShipperInvoice();
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_setGRNDetails"); 
            }
        }

        private void set_LoadShipperInvoice()
        {
            try
            {
                if (dgvShipperInvoice.Rows.Count > 0)
                {
                    dgvShipperInvoice.Rows.Clear();
                }

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(this.dgvShipperInvoice.MasterView);
                for (int intRow = 0; intRow < _BUS.getset_ShipperInvoice.Length; intRow++)
                {
                    rowInfo = new GridViewDataRowInfo(this.dgvShipperInvoice.MasterView);

                    rowInfo.Cells["invno"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["invno"]).ToString().Trim();
                    rowInfo.Cells["DONo"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["DONo"]).ToString().Trim();
                    rowInfo.Cells["CgneeID"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["CgneeID"]).ToString().Trim();
                    rowInfo.Cells["DOQty"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["DOQty"]).ToString().Trim();
                    rowInfo.Cells["insvalue"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["insvalue"]).ToString().Trim();
                    rowInfo.Cells["insvaluef"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["insvaluef"]).ToString().Trim();
                    rowInfo.Cells["tfcargorecinsID"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperInvoice[intRow]["tfcargorecinsID"]).ToString().Trim();
                    
                    dgvShipperInvoice.Rows.Add(rowInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadShipperInvoice");
            }
        }

        private void set_LoadShipperMeasurement()
        {
            try
            {
                if (dgvShipperMeasurement.Rows.Count > 0)
                {
                    dgvShipperMeasurement.Rows.Clear();
                }

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(this.dgvShipperMeasurement.MasterView);
                string strCode = string.Empty;
                for (int intRow = 0; intRow < _BUS.getset_ShipperMeasurement.Length; intRow++)
                {
                    rowInfo = new GridViewDataRowInfo(this.dgvShipperMeasurement.MasterView);
                    rowInfo.Cells["itemcode"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement [intRow]["itemcode"]).ToString().Trim();
                    rowInfo.Cells["itemdes"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["itemdes"]).ToString().Trim();
                    rowInfo.Cells["uomcode"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["uomcode"]).ToString().Trim();
                    rowInfo.Cells["actlength"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["actlength"]).ToString().Trim();
                    rowInfo.Cells["actwidth"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["actwidth"]).ToString().Trim();
                    rowInfo.Cells["actheight"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["actheight"]).ToString().Trim();
                    rowInfo.Cells["actqty"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["actqty"]).ToString().Trim();
                    rowInfo.Cells["actcbm"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["actcbm"]).ToString().Trim();
                    rowInfo.Cells["unitcbm"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_ShipperMeasurement[intRow]["unitcbm"]).ToString().Trim();
                    dgvShipperMeasurement.Rows.Add(rowInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadShipperMeasurement");
            }
        }

        private void set_LodGenMeasurementGrid()
        {
            try
            {
                if (dgvGenMeasurement.Rows.Count > 0)
                {
                    dgvGenMeasurement.Rows.Clear();
                }

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(this.dgvGenMeasurement.MasterView);
                string strCode = string.Empty ;
                for (int intRow = 0; intRow < _BUS.getset_GenMeasurement.Length; intRow++)
                {
                    rowInfo = new GridViewDataRowInfo(this.dgvGenMeasurement.MasterView);
                    rowInfo.Cells["tfcargorecdID"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["tfcargorecdID"]).ToString().Trim();
                    rowInfo.Cells["cargocode"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["cargocode"]).ToString().Trim();
                    rowInfo.Cells["cargodes"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["cargodes"]).ToString().Trim();
                    rowInfo.Cells["actqty"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["actqty"]).ToString().Trim();
                    strCode = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["uomcode"]).ToString().Trim();
                    rowInfo.Cells["actlength"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["actlength"]).ToString().Trim();
                    rowInfo.Cells["actwidth"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["actwidth"]).ToString().Trim();
                    rowInfo.Cells["actheight"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["actheight"]).ToString().Trim();
                    rowInfo.Cells["actcbm"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["actcbm"]).ToString().Trim();
                    rowInfo.Cells["stickno"].Value = clsGenFunction.get_checkStringNull(_BUS.getset_GenMeasurement[intRow]["stickno"]).ToString().Trim();
                    rowInfo.Cells["lightheavy"].Value = clsGenFunction.get_checkStringNull (_BUS.getset_GenMeasurement[intRow]["lightheavy"]).ToString().Trim();
                    rowInfo.Cells["fraitem"].Value =  _BUS.getset_GenMeasurement[intRow]["fraitem"];
                    rowInfo.Cells["dangood"].Value = _BUS.getset_GenMeasurement[intRow]["dangood"];

                    dgvGenMeasurement.Rows.Add(rowInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LodGenMeasurementGrid");
            }
        }

        private void set_clearFieldsConsignee()
        {

            txtDateconsignee.Text = string.Empty;
            txtTimeConsignee.Text = string.Empty;

            rtbPortOfDischarge.Document = new RadDocument();
            set_RichTextBoxOneLine();
            StringBuilder strAddress = new StringBuilder();
            
            rtbPortOfDischarge.Insert(strAddress.ToString());

          //  txtPortIDConsignee.Text = string.Empty;
            txtPOD.Text = string.Empty;
            txtTotalQty.Text = string.Empty;
            txtTotalCBM.Text = string.Empty;
            txtTotalWeight.Text = string.Empty;
            mskshipperQty.Value = string.Empty;
            mskshipperCBM.Value = string.Empty;
            mskshipperWeight.Value = string.Empty;

        }

        private void set_ShipperConsigneeAddress(DataRow[] drConsigneeDetails, ref RadRichTextBox rtAddress)
        {
            try
            {
               
                rtAddress.Document = new RadDocument();
                StringBuilder strAddress = new StringBuilder();
                set_RichTextBoxOneLine();
                strAddress.AppendLine(_BUS.get_CodeName("company", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["comid"]).ToString().Trim()) + " (" +
                                         clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["comid"]).ToString().Trim() + ")");

                if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline1"]).ToString().Trim() != string.Empty)
                {
                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline1"]).ToString().Trim());
                }

             //   strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline2"]).ToString().Trim());

                if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline2"]).ToString().Trim() != string.Empty)
                {
                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline2"]).ToString().Trim());
                }
                if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline3"]).ToString().Trim() != string.Empty)
                {
                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline3"]).ToString().Trim());
                }
                if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline3"]).ToString().Trim() != string.Empty)
                {
                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["addline3"]).ToString().Trim());
                }

                strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["poscode"]).ToString().Trim() + " " +
                                    _BUS.get_CodeName("city", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["citycode"]).ToString().Trim()) + " " +
                                    _BUS.get_CodeName("state", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["stacode"]).ToString().Trim().ToString()));
                strAddress.AppendLine("Tel No. " + clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["telpre"]).ToString().Trim() + "-" +
                                      clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["telno"]).ToString().Trim() +
                                      " Fax No. " + clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["faxpre"]).ToString().Trim() + "-" +
                                      clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["faxno"]).ToString().Trim());

                rtAddress.Insert(strAddress.ToString());

               

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " "); 
            }
        }

        private void set_ConsigneeDetailsAddressGRN(DataRow[] drConsigneeDetails)
        {
            try
            {
                if (drConsigneeDetails.Length > 0)
                {
                    txtDateconsignee.Text = Convert.ToDateTime(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["connotedate"]).ToString().Trim()).ToString("dd/MM/yyyy");
                    txtTimeConsignee.Text = Convert.ToDateTime(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["connotetime"]).ToString().Trim()).ToString("hh:mm:sstt");

                    rtbPortOfDischarge.Document = new RadDocument();
                    set_RichTextBoxOneLine();
                    StringBuilder strAddress = new StringBuilder();

                    _BUS.getset_ConsigneeID = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conid"]).ToString().Trim();

                    strAddress.AppendLine(_BUS.get_CodeName("company", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conid"]).ToString().Trim()) + " (" +
                                          clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conid"]).ToString().Trim() + ")");

                    if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline1"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline1"]).ToString().Trim());
                    }

                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline2"]).ToString().Trim());

                    if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline3"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline3"]).ToString().Trim());
                    }
                    if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline4"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline4"]).ToString().Trim());
                    }
                    if (clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline5"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conline5"]).ToString().Trim());
                    }

                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["conpostcode"]).ToString().Trim() + " " +
                                        _BUS.get_CodeName("city", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["concitycode"]).ToString().Trim()) + " " +
                                        _BUS.get_CodeName("state", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["constatecode"]).ToString().Trim().ToString()));
                    strAddress.AppendLine("Tel No. " + clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["contelpre"]).ToString().Trim() + "-" +
                                          clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["contelno"]).ToString().Trim() +
                                          " Fax No. " + clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["confaxpre"]).ToString().Trim() + "-" +
                                          clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["confaxno"]).ToString().Trim());

                    rtbPortOfDischarge.Insert(strAddress.ToString());

               //     txtPortIDConsignee.Text = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["portid"]).ToString().Trim();
                    txtPOD.Text = _BUS.get_CodeName("port", clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["portid"]).ToString().Trim());
                    txtTotalQty.Text = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["totqty"]).ToString().Trim();
                    txtTotalCBM.Text = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["totcbm"]).ToString().Trim();
                    txtTotalWeight.Text = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["totwei"]).ToString().Trim();
                    mskshipperQty.Value = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["shipqty"]).ToString().Trim();
                    mskshipperCBM.Value = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["shipcbm"]).ToString().Trim();
                    mskshipperWeight.Value = clsGenFunction.get_checkStringNull(drConsigneeDetails[0]["shipwei"]).ToString().Trim();

                }
                else
                {
                    set_clearFieldsConsignee();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ConsigneeDetailsAddress"); 
            }
        }

        //private void set_ConsigneeDetailsAddress()
        //{
        //    try
        //    {
        //        txtDateconsignee.Text = Convert.ToDateTime(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["connotedate"]).ToString().Trim()).ToString("dd/MM/yyyy");
        //        txtTimeConsignee.Text = Convert.ToDateTime(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["connotetime"]).ToString().Trim()).ToString("hh:mm:sstt");

        //        rtbPortOfDischarge.Document = new RadDocument();
        //        set_RichTextBoxOneLine();
        //        StringBuilder strAddress = new StringBuilder();

        //        strAddress.AppendLine(_BUS.get_CodeName("company", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conid"]).ToString().Trim()) + " (" +
        //                              clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conid"]).ToString().Trim() + ")");
              
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline1"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline1"]).ToString().Trim());
        //        }

        //        strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline2"]).ToString().Trim());
 
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline3"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline3"]).ToString().Trim());
        //        }
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline4"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline4"]).ToString().Trim());
        //        }
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline5"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline5"]).ToString().Trim());
        //        }

        //        strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conpostcode"]).ToString().Trim() + " " +
        //                            _BUS.get_CodeName("city", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["concitycode"]).ToString().Trim()) + " " +
        //                            _BUS.get_CodeName("state", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["constatecode"]).ToString().Trim().ToString()));
        //        strAddress.AppendLine("Tel No. "+clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["contelpre"]).ToString().Trim()+ "-"+
        //                              clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["contelno"]).ToString().Trim() +
        //                              " Fax No. " + clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["confaxpre"]).ToString().Trim()+ "-"+
        //                              clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["confaxno"]).ToString().Trim());

        //      rtbPortOfDischarge.Insert(strAddress.ToString());

        //        txtPortIDConsignee.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["portid"]).ToString().Trim();
        //        txtPortNameConsignee.Text = _BUS.get_CodeName("port", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["portid"]).ToString().Trim());
        //        txtTotalQty.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["totqty"]).ToString().Trim();
        //        txtTotalCBM.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["totcbm"]).ToString().Trim();
        //        txtTotalWeight.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["totwei"]).ToString().Trim();
        //        mskshipperQty.Value = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipqty"]).ToString().Trim();
        //        mskshipperCBM.Value = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipcbm"]).ToString().Trim();
        //        mskshipperWeight.Value = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipwei"]).ToString().Trim();

              

        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message + " set_ConsigneeDetails");
        //    }
        //}

        private void set_ClearShipperFields()
        {
            txtGRNo.Text = string.Empty;
            rtbPortOfLoading.Document = new RadDocument();
            set_RichTextBoxOneLine();
            StringBuilder strAddress = new StringBuilder();

         //   rtbShipperRefNo.ChangeParagraphLineSpacing(0);
            rtbPortOfLoading.Insert(strAddress.ToString());

            txtInternalVehicle.Text = string.Empty;
          //  rtbShipperRefNo.Text = string.Empty;
            txtShipperReference.Text = string.Empty;
            txtIssudeByID.Text = string.Empty;
            txtIssudeByName.Text = string.Empty;
            txtTermByID.Text = string.Empty;
            txtTermByName.Text = string.Empty;

            txtM3VerByName.Text = string.Empty;
            txtGRNVerByID.Text = string.Empty;


        }

        private void set_ShipperDetailsAddressGRN(DataRow[] drShipperDetails)
        {
            try
            {
                if (drShipperDetails.Length > 0)
                {
                    txtGRNo.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["connoteno"]).ToString().Trim();

                    _BUS.getset_ShipperID = clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipid"]).ToString().Trim();
                
                    rtbPortOfLoading.Document = new RadDocument();
                    set_RichTextBoxOneLine();
                    StringBuilder strAddress = new StringBuilder();

                //    rtbShipperRefNo.ChangeParagraphLineSpacing(0);

                    strAddress.AppendLine(_BUS.get_CodeName("company", clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipid"]).ToString().Trim()) +
                                          " (" + clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipid"]).ToString().Trim() + ")");

                    if (clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline1"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline1"]).ToString().Trim());
                    }
                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline2"]).ToString().Trim());

                    if (clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline3"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline3"]).ToString().Trim());
                    }
                    if (clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline4"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline4"]).ToString().Trim());
                    }
                    if (clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline5"]).ToString().Trim() != string.Empty)
                    {
                        strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipline5"]).ToString().Trim());
                    }


                    strAddress.AppendLine(clsGenFunction.get_checkStringNull(drShipperDetails[0]["shippostcode"]).ToString().Trim() + " " +
                                         _BUS.get_CodeName("city", clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipcitycode"]).ToString().Trim()) + " " +
                                         _BUS.get_CodeName("state", clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipstatecode"]).ToString().Trim().ToString()));


                    strAddress.AppendLine("Tel No. " + clsGenFunction.get_checkStringNull(drShipperDetails[0]["shiptelpre"]).ToString().Trim() + "-" +
                                          clsGenFunction.get_checkStringNull(drShipperDetails[0]["shiptelno"]).ToString().Trim() +
                                          " Fax No. " + clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipfaxpre"]).ToString().Trim() + "-" +
                                          clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipfaxno"]).ToString().Trim());


                    rtbPortOfLoading.Insert(strAddress.ToString());

                    set_GRNVerification(drShipperDetails);
                    set_CashBill();
                    set_BillAgent();
                    set_BillBranch();
                }
                else
                {
                    set_ClearShipperFields();
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ""); 
            }
        }

        private void set_GRNVerification(DataRow[] drShipperDetails)
        {
            try
            {
                txtInternalVehicle.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["vehplano"]).ToString().Trim();
                txtShipperReference.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["shipinvno"]).ToString().Trim();

                txtIssudeByID.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["issby"]).ToString().Trim();
                txtIssudeByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(drShipperDetails[0]["issby"]).ToString().Trim());
                txtTermByID.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["termverby"]).ToString().Trim();
                txtTermByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(drShipperDetails[0]["termverby"]).ToString().Trim());

                txtM3VerByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(drShipperDetails[0]["grnVerified"]).ToString().Trim());
                txtGRNVerByID.Text = clsGenFunction.get_checkStringNull(drShipperDetails[0]["grnVerified"]).ToString().Trim();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GRNVerification"); 
            }
        }

        //private void set_ShipperDetailsAddress()
        //{
        //    try
        //    {
        //     //   string a = txtDateconsignee.Text;

        //        txtGRNo.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["connoteno"]).ToString().Trim();
        //        rtbPortOfLoading.Document = new RadDocument();
        //        set_RichTextBoxOneLine();
        //        StringBuilder strAddress = new StringBuilder();

        //        rtbShipperRefNo.ChangeParagraphLineSpacing(0);

        //        strAddress.AppendLine(_BUS.get_CodeName("company", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipid"]).ToString().Trim()) + 
        //                              " (" + clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipid"]).ToString().Trim() +")");
              
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline1"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline1"]).ToString().Trim());
        //        }
        //            strAddress.AppendLine (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline2"]).ToString().Trim());

        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline3"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline3"]).ToString().Trim());
        //        }
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline4"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline4"]).ToString().Trim());
        //        }
        //        if (clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline5"]).ToString().Trim() != string.Empty)
        //        {
        //            strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline5"]).ToString().Trim()); 
        //        }

                    
        //        strAddress.AppendLine(clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shippostcode"]).ToString().Trim() + " " +
        //                             _BUS.get_CodeName("city", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipcitycode"]).ToString().Trim()) + " " +
        //                             _BUS.get_CodeName("state", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipstatecode"]).ToString().Trim().ToString()));


        //       strAddress.AppendLine("Tel No. " + clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shiptelpre"]).ToString().Trim() + "-" +
        //                             clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shiptelno"]).ToString().Trim() +
        //                             " Fax No. " + clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipfaxpre"]).ToString().Trim() + "-" +
        //                             clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipfaxno"]).ToString().Trim());


        //        rtbPortOfLoading.Insert(strAddress.ToString());
               
        //        txtInternalVehicle.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["vehplano"]).ToString().Trim();
        //        rtbShipperRefNo.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipinvno"]).ToString().Trim();
              
        //        txtIssudeByID.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["issby"]).ToString().Trim();
        //        txtIssudeByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["issby"]).ToString().Trim());
        //        txtTermByID.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["termverby"]).ToString().Trim();
        //        txtTermByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["termverby"]).ToString().Trim());

        //        txtM3VerByName.Text = _BUS.get_CodeName("user", clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["grnVerified"]).ToString().Trim());
        //        txtGRNVerByID.Text = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["grnVerified"]).ToString().Trim();
                        
        //        set_CashBill();
        //        set_BillAgent();
        //        set_BillBranch();

        //                   }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message + " frmGRN_set_ShipperDetails");
        //    }
        //}

        private void set_BillBranch()
        {
            try
            {
                string strCashBill = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["billbranch"]).ToString().Trim();
                if (strCashBill == "False" || strCashBill == string.Empty)
                {
                  //  chkBranhbilling.Checked = false;
                }
                else if (strCashBill == "True")
                {
                   // chkBranhbilling.Checked = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_BillBranch");
            }
        }

        private void set_BillAgent()
        {
            try
            {
                string strCashBill = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["billagent"]).ToString().Trim();
                if (strCashBill == "False" || strCashBill == string.Empty)
                {
                   // chkBillAgent.Checked = false;
                }
                else if (strCashBill == "True")
                {
                  //  chkBillAgent.Checked = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_BillAgent");
            }
        }

        private void set_CashBill()
        {
            try
            {
                string strCashBill = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["cashbill"]).ToString().Trim();
                if (strCashBill == "False" || strCashBill == string.Empty)
                {
                    //chkCashBill.Checked = false;
                }
                else if (strCashBill == "True")
                {
              //      chkCashBill.Checked = true;ssssssssssssssssssssssssssssssssssssssssssssssssssssssss
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_CashBill");
            }
        }

        private string getset_GRNNo
        {
            get
            {
                return strGRNNo;
            }
            set
            {
                strGRNNo = value;
            }
        }

        public frmGRN()
        {
            InitializeComponent();
            _BUS = new clsInterfaceGRN();
        }

        ~frmGRN()
        { }

        private void set_BackStage()
        {
            RadPageViewBackstageElement backStageElement = rvGRNProcessing.ViewElement as RadPageViewBackstageElement;
            StripViewItemContainer itemContainer = backStageElement.ItemContainer as StripViewItemContainer;
            StripViewItemLayout itemLayout = backStageElement.ItemContainer.ItemLayout as StripViewItemLayout;

            itemContainer.MinSize = new Size(80, 0);
        }

        private void set_GridRowHeight()
        {
            ((GridTableElement)this.dgvGenMeasurement.TableElement).RowHeight = 20;
            ((GridTableElement)this.dgvShipperInvoice.TableElement).RowHeight = 20;
            ((GridTableElement)this.dgvShipperMeasurement.TableElement).RowHeight = 20;
            ((GridTableElement)this.dgvTempGRN.TableElement).RowHeight = 20;
        }

        private void set_SetControls()
        {
            try
            {
                set_RichTextBoxOneLine();
                set_GridRowHeight();

                rtbPortOfLoading.DocumentView.Caret.Width = 0;
                rtbPortOfDischarge.DocumentView.Caret.Width = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_SetControls");
            }
        }

        private void set_LoadPortOrigin()
        {
            try
            {
                using (clsInterfaceSalesTerm _BUSfindPort = new clsInterfaceSalesTerm())
                {
                    DataTable dt = new DataTable();

                    dt = _BUSfindPort.get_Ports();
                    mcmbOrigin.EditorControl.LoadElementTree();
                    mcmbOrigin.DataSource = dt;

                    for (int intIndex = 0; intIndex < dt.Columns.Count; intIndex++)
                    {
                        mcmbOrigin.MultiColumnComboBoxElement.Columns[intIndex].BestFit();
                    }

                    mcmbOrigin.MultiColumnComboBoxElement.DropDownWidth = 300;
                    mcmbOrigin.MultiColumnComboBoxElement.DropDownHeight = 150;
                    mcmbOrigin.SelectedIndex = -1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadPortOrigin");
            }
            
        }

        private void set_LoadPortDestination()
        {
            try
            {
                DataTable dt = new DataTable();
                using (clsInterfaceSalesTerm _BUSfindPort = new clsInterfaceSalesTerm())
                {
                    dt = _BUSfindPort.get_Ports();
                    mcmbDestination.EditorControl.LoadElementTree();
                    mcmbDestination.DataSource = dt;

                    for (int intIndex = 0; intIndex < dt.Columns.Count; intIndex++)
                    {
                        mcmbDestination.MultiColumnComboBoxElement.Columns[intIndex].BestFit();
                    }

                    mcmbDestination.MultiColumnComboBoxElement.DropDownWidth = 300;
                    mcmbDestination.MultiColumnComboBoxElement.DropDownHeight = 150;
                    mcmbDestination.SelectedIndex = -1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadPortDestination"); 
            }
        }
        
        private void set_PortOriginDestination()
        {
            this.mcmbDestination.SelectedIndexChanged -= new System.EventHandler(this.mcmbDestination_SelectedIndexChanged);
            this.mcmbOrigin.SelectedIndexChanged -= new System.EventHandler(this.mcmbOrigin_SelectedIndexChanged);

            set_LoadPortDestination();
            set_LoadPortOrigin();

            this.mcmbDestination.SelectedIndexChanged += new System.EventHandler(this.mcmbDestination_SelectedIndexChanged);
            this.mcmbOrigin.SelectedIndexChanged += new System.EventHandler(this.mcmbOrigin_SelectedIndexChanged);  
        }

        private void frmGRN_Load(object sender, EventArgs e)
        {
            try
            {
                ((GridTableElement)this.dgvDestination.TableElement).RowHeight = 20;
                ((GridTableElement)this.dgvOrigin.TableElement).RowHeight = 20;

                set_PortOriginDestination();

                set_SetControls();
                clsGenFunction.set_BackStage(ref rvGRNProcessing);

                getset_Update = false;
                getset_New = false;
                mcmbOrigin.Text = "PK";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmGRN_Load"); 
            }
        }

        private void set_RichTextBoxOneLine()
        {
            //rtbShipperRefNo.ChangeParagraphLineSpacing(0);
            rtbPortOfLoading.ChangeParagraphLineSpacing(0);
            rtbPortOfDischarge.ChangeParagraphLineSpacing(0);
        }

        private void radButton3_Click(object sender, EventArgs e)
        {
            using (frmSalesTerm x = new frmSalesTerm())
            {
                x.StartPosition = FormStartPosition.CenterScreen;
                x.ShowDialog();
            }
        }

        private void radButton4_Click(object sender, EventArgs e)
        {
            using (frmAdditionalServices x = new frmAdditionalServices())
            {
                x.StartPosition = FormStartPosition.CenterScreen;
                x.ShowDialog();
            }
        }

        private void radButton5_Click(object sender, EventArgs e)
        {
            using (frmQoutation x = new frmQoutation())
            {
                x.StartPosition = FormStartPosition.CenterScreen;
                x.ShowDialog();
            }
        }

        private void radButton6_Click(object sender, EventArgs e)
        {
            using (frmShipperConsigneeRelationship x = new frmShipperConsigneeRelationship())
            {
                x.StartPosition = FormStartPosition.CenterScreen;
                x.ShowDialog();
            }
        }

        private void frmGRN_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            GC.Collect();
            GC.WaitForFullGCComplete();
            GC.Collect();
        }

        private void txtCompanyID_MouseEnter(object sender, EventArgs e)
        {

        }

        private void set_NextPage(ref RadPageViewPage Page)
        {
            RadPageViewPage page = new RadPageViewPage();
            page = Page;
            rvGRNProcessing.SelectedPage = page;
        }

        private void btnInformation_Click(object sender, EventArgs e)
        {
            set_NextPage(ref pvpSalesTerm);
        }

        private void btnSalesTerm_Click(object sender, EventArgs e)
        {
           set_NextPage(ref pvpShipperInvoice);
        }

        private void btnInvoice_Click(object sender, EventArgs e)
        {
           set_NextPage(ref pvpGeneralMeasurement);
        }

        private void btnGenMeasurement_Click(object sender, EventArgs e)
        {
           set_NextPage(ref pvpShipperMeasurement);
        }

        private void btnShipperMeasurement_Click(object sender, EventArgs e)
        {
           set_NextPage(ref pvpPreview);
        }

        private void txtShipperName_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    get_FindCompany();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " txtShipperName_KeyUp");
            }
        }

        private string get_FindCompany()
        {
            string strFindCompany = string.Empty;
            try
            {
                using (frmFindCompany addressBook = new frmFindCompany("Company"))
                {
                    DialogResult dlResult = addressBook.ShowDialog();
                    if (dlResult == DialogResult.OK)
                    {
                        strFindCompany = addressBook.get_CompanyID + "-" + addressBook.get_CompanyName;
                        getset_PortID = addressBook.get_PortID;
                        #region Nothing
                        //frmModule.frmAddressBook.set_RefreshAll();

                        //getset_CompanyID = addressBook.get_CompanyIDHQ().Trim();
                        //getset_CompanyType = addressBook.get_CompanyType.Trim();

                        //frmModule.frmAddressBook.getset_CompanyID = getset_CompanyID;
                        //frmModule.frmAddressBook.getset_CompanyType = getset_CompanyType;
                        //    frmModule.frmAddressBook.set_AddressbookFields();
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_FindCompany");
            }

            return strFindCompany;
        }

        private void txtShipperName_Enter(object sender, EventArgs e)
        {
            get_FindCompany();
        }

        private void txtPortNameConsignee_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Tab)
            {
               set_NextPage(ref pvpSalesTerm);
            }
        }

        private void txtPortNameConsignee_TabIndexChanged(object sender, EventArgs e)
        {
                set_NextPage(ref pvpSalesTerm);
        }

        private void btnInformation_Enter(object sender, EventArgs e)
        {
           set_NextPage(ref pvpSalesTerm);
        }

        private void btnInformation2_Click(object sender, EventArgs e)
        {
            
            set_NextPage(ref pvpSalesTerm);
        }

        private bool get_CheckFreight()
        {
            bool bolStatus = false;

            if (ddlFreight.Text.Trim() != string.Empty && ddlFreight.Text != null)
            {
                if (ddlFreight.Text.Trim() == "Air Freight" ||
                    ddlFreight.Text.Trim() == "Warehouse & Logistics" ||
                    ddlFreight.Text.Trim() == "Sea / Ocean" ||
                    ddlFreight.Text.Trim() == "International" ||
                    ddlFreight.Text.Trim() == "Domestics")
                {
                    bolStatus = true;
                }
            }
            return bolStatus;
        }

        private bool get_CheckType()
        {
            bool bolStatus = false;
            if (ddlLC_FCL.Text.Trim() != string.Empty)
            {
                if (ddlLC_FCL.Text.Trim() == "LCL" || ddlLC_FCL.Text.Trim() == "FCL")
                {
                    bolStatus = true;
                }
            }

            return bolStatus;
        }

        private bool get_CheckPOL_PODRequiredFields()
        {
            bool bolstatus = false;
            try
            {
                if (get_CheckFreight() == true)
                {
                    if (get_CheckType() == true)
                    {
                        //if (txtShipperCompanyID.Text.Trim() != string.Empty &&
                        //    txtShipperCompanyName.Text.Trim() != string.Empty)
                        //{
                        //    if (rtbPortOfLoading.Text.Trim() != string.Empty)
                        //    {
                        //        bolstatus = true;
                        //    }
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_CheckPOL_PODRequiredFields"); 
            }

            return bolstatus;
        }

        private void btnInformation2_Enter(object sender, EventArgs e)
        {
            //if (get_CheckPOL_PODRequiredFields() == true)
            //{
                set_NextPage(ref pvpSalesTerm);
           // }
        }

        private void btnSalesTerm_Enter(object sender, EventArgs e)
        {
            set_NextPage(ref pvpShipperInvoice);

        }

        private void btnNextInvoice_Click(object sender, EventArgs e)
        {
            set_NextPage(ref pvpShipperMeasurement);
        }

        private void btnNextInvoice_Enter(object sender, EventArgs e)
        {
            set_NextPage(ref pvpShipperMeasurement);
        }

        private void btnNextShipperMeasurement_Click(object sender, EventArgs e)
        {
            set_NextPage(ref pvpGeneralMeasurement);
        }

        private void btnNextShipperMeasurement_Enter(object sender, EventArgs e)
        {
            set_NextPage(ref pvpGeneralMeasurement);
        }

        private void btnNextGenMeasurement_Click(object sender, EventArgs e)
        {
            set_NextPage(ref pvpPreview);
        }

        private void btnNextGenMeasurement_Enter(object sender, EventArgs e)
        {
            set_NextPage(ref pvpPreview);
        }

        private void btnNextPreview_Click(object sender, EventArgs e)
        {
            set_NextPage(ref pvpTempGRNMemo);
        }

        private void btnNextPreview_Enter(object sender, EventArgs e)
        {
           set_NextPage(ref pvpTempGRNMemo);
        }

        private void btnfindCompanyShipper_Click(object sender, EventArgs e)
        {
            try
            {
                set_RichTextBoxOneLine();
                string strAllID = get_FindCompany();
                mcmbOrigin.Text = getset_PortID;  
                getset_ShipperCompanyID = strAllID.Substring(0, strAllID.IndexOf("-"));
                _BUS.getset_ShipperID = strAllID.Substring(0, strAllID.IndexOf("-"));

                getset_ShipperCompanyName = strAllID.Substring(strAllID.IndexOf("-") + 1, strAllID.Length - strAllID.IndexOf("-") - 1);
                set_ShipperConsigneeAddress(_BUS.get_ShipperConsigneeAddress(getset_ShipperCompanyID, "shipper"), ref rtbPortOfLoading);
                getset_PortID = string.Empty;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " btnfindCompanyShipper_Click"); 
            }
        }

        private void btnfindCompanyConsignee_Click(object sender, EventArgs e)
        {
            try
            {
                set_RichTextBoxOneLine();
                string strAllID = get_FindCompany();
                mcmbDestination.Text = getset_PortID; 
                getset_ConsigneeCompanyID = strAllID.Substring(0, strAllID.IndexOf("-"));
                _BUS.getset_ConsigneeID = strAllID.Substring(0, strAllID.IndexOf("-"));

                getset_ConsigneeCompanyName = strAllID.Substring(strAllID.IndexOf("-") +1, strAllID.Length - strAllID.IndexOf("-")-1);
                set_ShipperConsigneeAddress(_BUS.get_ShipperConsigneeAddress(getset_ConsigneeCompanyID, "consignee"), ref rtbPortOfDischarge);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " btnfindCompanyConsignee_Click");
            }
        }

        private bool set_CommitAdditionalServices()
        {
           return this.AdditionalServices.set_CommitUpdateSaveAdditionalServices(); 
        }
        private bool set_CommitAdditinalServicesHeader()
        {
            return this.AdditionalServices.set_CommitUpdateSaveAdditionalServicesHeader();
        }

        public void set_NewGRNFields()
        {
            try
            {
                getset_GRNNo = string.Empty;
                _BUS.getset_GRNNo = string.Empty;

                //sets and checks records for GRN
                if (_BUS.set_GRNMain() == true)
                {
                    //sets and checks records for GRN General Measurement
                    if (_BUS.set_GeneralMeasurment() == true)
                    {
                        //sets and checks records for Shipper Measurement
                        if (_BUS.set_ShipperMeasurment() == true)
                        {
                            //sets and checks records for Shipper Invoice
                            if (_BUS.set_ShipperInvoice() == true)
                            {
                                //the the IO for shipper
                                set_ShipperDetailsAddressGRN(_BUS.getset_GRNMainDetails);
                                //the the IO for consignee
                                set_ConsigneeDetailsAddressGRN(_BUS.getset_GRNMainDetails);
                                //set datagrid for General Measurement
                                set_LodGenMeasurementGrid();
                                //set datagrid for Shipper Measurement
                                set_LoadShipperMeasurement();
                                //set datagrid for Shipper Invoice
                                set_LoadShipperInvoice();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_NewGRNFields"); 
            }
        }

        private void set_ddlSalesTerm_SelectedIndexChanged()
        {
            try
            {
                if (mcmbOrigin.Text.Trim() != string.Empty &&
                    mcmbDestination.Text.Trim() != string.Empty)
                {
                    if (set_findChargesSalesTerm() == true)
                    {
                        if (ddlSalesTerm.Text.Trim() == "DTD")
                        {
                            txtShipperID.Text = getset_ShipperCompanyID;
                            txtShipperName.Text = getset_ShipperCompanyName;
                        }
                        else if (ddlSalesTerm.Text.Trim() == "EX")
                        {
                            txtShipperID.Text = getset_ShipperCompanyID;
                            txtShipperName.Text = getset_ShipperCompanyName;

                            txtConsigneeID.Text = getset_ConsigneeCompanyID;
                            txtConsigneeName.Text = getset_ConsigneeCompanyName;
                        }
                        else if (ddlSalesTerm.Text.Trim() == "FOB")
                        {
                            txtShipperID.Text = getset_ShipperCompanyID;
                            txtShipperName.Text = getset_ShipperCompanyName;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("POL or POD is missing.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ddlSalesTerm_SelectedIndexChanged");
            }
        }

        private void ddlSalesTerm_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            set_ddlSalesTerm_SelectedIndexChanged();
        }

        private bool set_findChargesSalesTerm()
        {
            bool bolStatus = false;
            try
            {
                using (frmFindSalesTermHeader frmFindSalesTerms = new frmFindSalesTermHeader())
                {
                    frmFindSalesTerms.getset_PortOfDestination = mcmbDestination.Text.Trim();
                    frmFindSalesTerms.getset_PortOfOriginID = mcmbOrigin.Text.Trim();
                    frmFindSalesTerms.getset_SalesTerm = ddlSalesTerm.Text.Trim();
                    DialogResult = frmFindSalesTerms.ShowDialog();
                    if (DialogResult == DialogResult.OK)
                    {
                        using (clsInterfaceSalesTerm SalesTerm = new clsInterfaceSalesTerm())
                        {
                            getset_SalesTermSetupHeaderID = frmFindSalesTerms.get_HeaderID;
                            if (SalesTerm.set_RecordsOriginDestination(getset_SalesTermSetupHeaderID) == true)
                            {
                                set_LoadGridOriginDestination(ref dgvOrigin, SalesTerm.get_OrginCharges, SalesTerm);
                                set_LoadGridOriginDestination(ref dgvDestination, SalesTerm.get_DestinationCharges, SalesTerm);  
                                
                                gbDestinationCharges.Text = gbDestinationCharges.Text + " - Port: " + mcmbDestination.Text;
                                gbOriginCharges.Text = gbOriginCharges.Text + " - Port: " + mcmbOrigin.Text;
                                bolStatus = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_findChargesSalesTerm");
            }
            return bolStatus;
        }

        private bool set_LoadGridOriginDestination(ref RadGridView dgvGrid, DataRow[] drSource, clsInterfaceSalesTerm clsIST)
        {
            bool bolStatus = false;
            try
            {
                if (dgvGrid.Rows.Count > 0)
                { dgvGrid.Rows.Clear(); }

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                for (int intI = 0; intI < drSource.Length; intI++)
                {
                    rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                    for (int intC = 0; intC < dgvGrid.Columns.Count; intC++)
                    {
                        if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("column") == false
                            && dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("description") == false)
                        {
                            rowInfo.Cells[dgvGrid.Columns[intC].Name].Value = drSource[intI][dgvGrid.Columns[intC].Name];
                        }
                        else if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("description") == true)
                        {
                            rowInfo.Cells[dgvGrid.Columns[intC].Name].Value = clsIST.get_ChargeDescription(clsGenFunction.get_checkStringNull(drSource[intI]["ccitemcode"]));
                        }
                    }
                    dgvGrid.Rows.Add(rowInfo);
                }
              //  dgvGrid.BestFitColumns();
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message + " set_LoadGridOriginDestination");
            }

            return bolStatus;
        }

        //private bool set_LoadGridOriginDestination(ref RadGridView dgvGrid, DataRow[] drSource, clsInterfaceSalesTerm clsIST)
        //{
        //    bool bolStatus = false;
        //    try
        //    {
        //        if (dgvGrid.Rows.Count > 0)
        //        { dgvGrid.Rows.Clear(); }

        //        GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
        //        for (int intI = 0; intI < drSource.Length; intI++)
        //        {
        //            rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
        //            for (int intC = 0; intC < dgvGrid.Columns.Count; intC++)
        //            {
        //                if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("column") == false)
        //                {
        //                    if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("Description") == false)
        //                    {
        //                        rowInfo.Cells[dgvGrid.Columns[intC].Name].Value = drSource[intI][dgvGrid.Columns[intC].Name];

        //                    }
        //                    else if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("Description") == true)
        //                    {
        //                        rowInfo.Cells["Description"].Value = clsIST.get_ChargeDescription(clsGenFunction.get_checkStringNull(drSource[intI]["ccitemcode"]));
        //                    }
        //                }

        //            }
        //            dgvGrid.Rows.Add(rowInfo);
        //        }
        //        dgvGrid.BestFitColumns();
        //        bolStatus = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.InnerException.Message + " set_LoadGridOrigin");
        //    }

        //    return bolStatus;
        //}

        private void mcmbOrigin_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtPOL.Text = mcmbOrigin.EditorControl.Rows[mcmbOrigin.SelectedIndex].Cells[1].Value.ToString();  
        }

        private void mcmbDestination_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtPOD.Text = mcmbDestination.EditorControl.Rows[mcmbDestination.SelectedIndex].Cells[1].Value.ToString();  
        }

        private bool set_CommitUpdateSaveAdditionalServices()
        {
           return AdditionalServices.set_CommitUpdateSaveAdditionalServices(); 
        }

        public void set_FindAdditionalServices()
        {
            try
            {
                using (frmAdditionalServices addServices = new frmAdditionalServices())
                {
                    if (getset_ShipperCompanyID != string.Empty &&
                        getset_ConsigneeCompanyID != string.Empty && getset_SalesTermSetupHeaderID != string.Empty)
                    {
                        addServices.set_ShipperID = getset_ShipperCompanyID;
                        addServices.set_ShipperName = getset_ShipperCompanyName;
                        addServices.set_ConsigneeID = getset_ConsigneeCompanyID;
                        addServices.set_ConsigneeName = getset_ConsigneeCompanyName;
                        addServices.set_3rdPartyID = txt3rdPartyID.Text.Trim();
                        addServices.set_3rdPartyName = txt3rdPartyName.Text.Trim();
                        addServices.getset_PortID = mcmbDestination.Text.Trim(); 
                        addServices.getset_GoodReceivedNote = txtGRNo.Text.Trim();
                        addServices.set_3rdParty = txt3rdPartyID.Text.Trim();
                        addServices.getset_SalesTermSetupHeaderID = getset_SalesTermSetupHeaderID;

                        DialogResult result = addServices.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            this.AdditionalServices = addServices.get_AdditionalServicesBUS;
                            using (clsInterfaceSalesTerm SalesTerm = new clsInterfaceSalesTerm())
                            {
                                set_LoadGridOriginDestinationRefToGrid(ref dgvAdditionalChargesOriginx, addServices.get_OrigindtCharges, SalesTerm);
                            }
                        }
                        else
                        {
                            AdditionalServices = null;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Required fields are no complete.");
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_FindAdditionalServices");
            }
        }

        private void btmAdditionalServices_Click(object sender, EventArgs e)
        {
           
        }

        private DataTable get_GridColumns(RadGridView dgvGrid)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("ColName", typeof(string));
            DataRow drInsert;
            for (int intCol = 0; intCol < dgvGrid.Columns.Count; intCol++)
            {
                if (dgvGrid.Columns[intCol].Name.ToString().ToLower().Contains("column") == false)
                {
                    drInsert = dt.NewRow();
                    drInsert["ColName"] = dgvGrid.Columns[intCol].Name;
                    dt.Rows.Add(drInsert);
                }
            }
            return dt;
        }

        private void set_ClearLoadGridOriginDestinationRefToGrid(ref RadGridView dgvGrid)
        {
            if (dgvGrid.Rows.Count > 0)
            {
                dgvGrid.Rows.Clear();
            }
        }

        private bool set_LoadGridOriginDestinationRefToGrid(ref RadGridView dgvGrid, DataTable dtSource, clsInterfaceSalesTerm SalesTerm)
        {
            bool bolStatus = false;
            int intCol = 0;
            try
            {
                DataTable dtcolumns = get_GridColumns(dgvGrid);
                DataRow[] drCheck = { };

                set_ClearLoadGridOriginDestinationRefToGrid(ref dgvGrid);

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                for (int intRow = 0; intRow < dtSource.Rows.Count; intRow++)
                {
                    //rowInfo
                    rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                    for (intCol = 0; intCol < dgvGrid.Columns.Count; intCol++)
                    {
                        drCheck = dtcolumns.Select("ColName = '" + dtSource.Columns[intCol].ColumnName + "'");
                        if (drCheck.Length > 0)
                        {
                            rowInfo.Cells[dtSource.Columns[intCol].ColumnName].Value = dtSource.Rows[intRow][dtSource.Columns[intCol].ColumnName];
                        }
                    }
                    dgvGrid.Rows.Add(rowInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadGridOriginDestinationRefToGrid");
            }
            return bolStatus;
        }

        private void set_SelectedPagedChangedpvpPreview()
        {
            try
            {
                if (getset_SalesTermSetupHeaderID != string.Empty &&
                           getset_ShipperCompanyID != string.Empty &&
                           getset_ConsigneeCompanyID != string.Empty)
                {
                    rrbgGRN.Items["rbeGRNAdditionalServices"].Enabled = true;
                }
                else
                {
                    rrbgGRN.Items["rbeGRNAdditionalServices"].Enabled = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_SelectedPagedChangedpvpPreview"); 
            }
        }

        private void rvGRNProcessing_SelectedPageChanged(object sender, EventArgs e)
        {
            if (rvGRNProcessing.SelectedPage.Name == "pvpSalesTerm")
            {
                if (ddlSalesTerm.Text.Trim() == "DTD")
                { 
                  
                }
            }

            if (rvGRNProcessing.SelectedPage.Name == "pvpPreview")
            {
                set_SelectedPagedChangedpvpPreview();
            }
            else
            {
                rrbgGRN.Items["rbeGRNAdditionalServices"].Enabled = false;
            }
        }

        private void chk3rdPartyBilling_ToggleStateChanged(object sender, StateChangedEventArgs args)
        {
            try
            {
                if (chk3rdPartyBilling.Checked == true)
                { 
                    //find 3rd party biller here
                    //if found clear the fields of shipper or consignee id and company name
                    using (frmfind3rdPartyBiller biller = new frmfind3rdPartyBiller())
                    {
                        DialogResult dialog = biller.ShowDialog();
                        if (dialog == DialogResult.OK)
                        {
                            txtShipperID.Text = string.Empty;
                            txtConsigneeID.Text = string.Empty;
                            txtShipperName.Text = string.Empty;
                            txtConsigneeName.Text = string.Empty;
                        }
                        else
                        {
                            chk3rdPartyBilling.Checked = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " chk3rdPartyBilling_ToggleStateChanged"); 
            }
        }

        public void set_DisplayPreviousTransactions()
        {
            try
            {
                if (mcmbOrigin.Text.Trim() != string.Empty &&
                        mcmbDestination.Text.Trim() != string.Empty)
                {
                    using (frmCommonTransaction CommonTransact = new frmCommonTransaction())
                    {
                        CommonTransact.set_ConsigneeCompanyID = getset_ConsigneeCompanyID;
                        CommonTransact.set_ConsingeeCompanyName = getset_ConsigneeCompanyName;

                        CommonTransact.set_ShipperCompanyID = getset_ShipperCompanyID;
                        CommonTransact.set_ShipperCompanyName = getset_ShipperCompanyName;

                        CommonTransact.set_PortOfOrigin = mcmbOrigin.Text.Trim();
                        CommonTransact.set_PortOfDestination = mcmbDestination.Text.Trim();

                        CommonTransact.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Origin and Destination Details is incomplete, try again."); 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_DisplayPreviousTransactions");
            }
        }

        private void btnSCRelationship_Click(object sender, EventArgs e)
        {
            
        }

        private void ddlSalesTerm_SelectedValueChanged(object sender, EventArgs e)
        {
            set_ddlSalesTerm_SelectedIndexChanged();
        }

        private void set_GeneralMeasurement()
        {
            try
            {
                using (frmFindCompany find = new frmFindCompany("GeneralMeasurement"))
                {
                    DialogResult dr = find.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        dgvGenMeasurement.CurrentRow.Cells["cargodes"].Value = find.get_GenMeasurmentName;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GeneralMeasurement"); 
            }
        }

        private void dgvGenMeasurement_CellClick(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 1)
                {
                    set_GeneralMeasurement();
                }
                else if (e.ColumnIndex == 3)
                {
                    set_FindKOP("GeneralMeasurement", ref dgvGenMeasurement);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " dgvGenMeasurement_CellClick"); 
            }
        }

        private void set_ShipperMeasurement()
        {
            try
            {
                using (frmFindCompany find = new frmFindCompany("ShipperMeasurement"))
                {
                    DialogResult dr = find.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        dgvShipperMeasurement.CurrentRow.Cells["itemdes"].Value = find.get_ShipperMeasurmentName;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ShipperMeasurement"); 
            }
        }

        private void dgvShipperMeasurement_CellClick(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 1)
                {
                    set_ShipperMeasurement();
                }
                else if (e.ColumnIndex == 3)
                {
                    set_FindKOP("ShipperMeasurement", ref dgvShipperMeasurement);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ""); 
            }
        }

        private void set_FindKOP(string strType, ref RadGridView dgvGrid)
        {
            try
            {
                using (frmFindCompany find = new frmFindCompany("KOP"))
                {
                    DialogResult dr = find.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        if (strType == "ShipperMeasurement")
                        {
                            //dgvGrid.CurrentRow.Cells[""].Value = find.get_Code;
                            dgvGrid.CurrentRow.Cells["uomcode"].Value = find.get_Code;
                        }
                        else if (strType == "GeneralMeasurement")
                        {
                           // dgvGrid.CurrentRow.Cells[""].Value = find.get_Code;
                            dgvGrid.CurrentRow.Cells["uomcode"].Value = find.get_Code;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_FindKOP"); 
            }
        }

        private bool set_UpdatetfCargoRec()
        {
            bool bolStatus = false;
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_UpdatetfCargoRec"); 
            }
            return bolStatus;
        }

        private bool set_GenerateGRN()
        {
            bool bolStatus = false;
            try
            {
                using (clsGRNGenerator genGRN = new clsGRNGenerator())
                {
                   genGRN.set_DAL = _BUS.get_DAL_Transactions;
                   if (txtGRNo.Text.Trim() == string.Empty)
                   {
                       txtGRNo.Text = genGRN.GetGRNNo("grn", mcmbDestination.Text.Trim());
                       settfCargoRec.connoteno = txtGRNo.Text.Trim();
                       getset_GRNNo = txtGRNo.Text.Trim();
                       _BUS.getset_GRNNo = getset_GRNNo;
                   }
                   bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GenerateGRN"); 
            }
            return bolStatus;
        }

        public bool set_GenerateSetGRN()
        {
            bool bolStatus = false;
            try
            {
                string strGRN = string.Empty;
                settfCargoRec = new tfcargorec();

                if (getset_New == true || getset_Update == true)
                {
                    if (set_GenerateGRN() == true)
                    {
                        if (set_ShipperReferenceInvoiceTransfer() == true)
                        {
                           if (set_GeneralMeasurementTransfer() == true)
                           {
                                 if (set_ShipperConsigneeMeasurementDates() == true)
                                {
                                   if (set_ShipperConsigneeAddress() == true)
                                   {
                                       settfCargoRec.connoteno = getset_GRNNo;
                                       if (_BUS.set_InsertUpdateRecordsLinqTfcargorec(txtGRNo.Text.Trim(), settfCargoRec) == true)
                                       {
                                           if (_BUS.set_UpdateShipperInvoice() == true)
                                           {
                                               getset_New = false;
                                               getset_Update = true;
                                               set_ReloadGRNDetails(txtGRNo.Text.Trim());
                                               bolStatus = true;
                                           }
                                       }
                                   }
                               }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GenerateSetGRN"); 
            }
            return bolStatus;
        }

        private bool set_ShipperReferenceInvoiceTransfer()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.refno = txtShipperReference.Text.Trim();
                bolStatus = _BUS.set_TransferShipperInvoice(dgvShipperInvoice);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ShipperReference"); 
            }

            return bolStatus;
        }

        private bool set_GeneralMeasurementTransfer()
        {
            bool bolStatus = false;
            try
            {
                if (set_GeneralMeasurementTotals() == true)
                {
                    bolStatus = _BUS.set_TransferGeneralMeasurement(dgvGenMeasurement);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GeneralMeasurementTransfer");
            }

            return bolStatus;
        }

        private bool set_ShipperConsigneeAddress()
        {
            bool bolStatus = false;
            try
            {
                if (getset_New == true && getset_Update ==false )
                {
                    if (set_NewShipperAddress() == true)
                    {//convert this to bool from void
                        if (set_NewConsigneeAddress() == true)
                        {
                            bolStatus = true;
                        }//convert this to bool from void
                    }
                }
                
                if (getset_Update == true && getset_New == false)
                {
                    if (set_CurrentShipperAddress() == true)
                    {
                        if (set_CurrentConsigneeAddress() == true)
                        {
                            bolStatus = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ShipperConsigneeAddress"); 
            }
            return bolStatus;
        }

        private bool set_ShipperConsigneeMeasurementDates()
        {
            bool bolStatus = false;
            try
            {
                if (set_ShipperMeasurementTotals() == true)
                {
                    //if (set_GeneralMeasurementTotals() == true)
                    //{//convert this to bool from void
                        if (set_GRNDateTimeVeheclePort() == true)
                        {
                            bolStatus = true;
                        }//convert this to bool from void
                    }
               // }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GRNValues"); 
            }
            return bolStatus;
        }

        private bool set_ShipperMeasurementTotals()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.shipcbm = Convert.ToDecimal(mskshipperCBM.Value);
                settfCargoRec.shipwei = Convert.ToDecimal(mskshipperWeight.Value);
                settfCargoRec.shipqty = Convert.ToInt32(mskshipperQty.Value);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ShipperMeasurementTotals"); 
            }
            return bolStatus;
        }

        private bool set_GeneralMeasurementTotals()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.stickno = txtStickerNo.Text.Trim();
                settfCargoRec.totqty = Convert.ToInt32(txtTotalQty.Value);
                settfCargoRec.totcbm = Convert.ToDecimal(txtTotalCBM.Value);
                settfCargoRec.totwei = Convert.ToDecimal(txtTotalWeight.Value);
                settfCargoRec.insvaluef = Convert.ToDecimal(mskFragile.Value);
                settfCargoRec.insvalue = Convert.ToDecimal(mskNonFragile.Value);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GeneralMeasurementTotals"); 
            }
            return bolStatus;
        }

        private bool set_GRNDateTimeVeheclePort()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.connoteno = txtGRNo.Text.Trim();
                settfCargoRec.connotedate = clsGenFunction.get_DateDBServerFormat(_BUS.get_DAL_Transactions);
                settfCargoRec.connotetime = clsGenFunction.get_DateDBServerFormat(_BUS.get_DAL_Transactions).ToLocalTime();
                settfCargoRec.vehplano = txtInternalVehicle.Text.Trim();
                settfCargoRec.grntypecode = "LCL";
                settfCargoRec.stickno = txtStickerNo.Text.Trim();
                settfCargoRec.portid = mcmbDestination.Text.Trim();
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GRNDateTimeVehecle"); 
            }
            return bolStatus;
        }

        public bool set_CurrentShipperAddress()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.shipid = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipid"]);
                settfCargoRec.shipline1 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline1"]);
                settfCargoRec.shipline2 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline2"]);
                settfCargoRec.shipline3 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline3"]);
                settfCargoRec.shipline4 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipline4"]);
                settfCargoRec.shipareacode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipareacode"]);
                settfCargoRec.shipcitycode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipcitycode"]);
                settfCargoRec.shippostcode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shippostcode"]);
                settfCargoRec.shipstatecode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipstatecode"]);
                settfCargoRec.shiptelno = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shiptelno"]);
                settfCargoRec.shiptelpre = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shiptelpre"]);
                settfCargoRec.shipfaxpre = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipfaxpre"]);
                settfCargoRec.shipfaxno = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["shipfaxno"]);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ""); 
            }
            return bolStatus;
        }

        public bool set_CurrentConsigneeAddress()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.conid = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conid"]);
                settfCargoRec.conline1 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline1"]);
                settfCargoRec.conline2 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline2"]);
                settfCargoRec.conline3 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline3"]);
                settfCargoRec.conline4 = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conline4"]);

                settfCargoRec.conareacode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conareacode"]);
                settfCargoRec.concitycode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["concitycode"]);
                settfCargoRec.conpostcode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["conpostcode"]);
                settfCargoRec.constatecode = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["constatecode"]);

                settfCargoRec.contelno = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["contelno"]);
                settfCargoRec.contelpre = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["contelpre"]);
                settfCargoRec.confaxpre = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["confaxpre"]);
                settfCargoRec.confaxno = clsGenFunction.get_checkStringNull(_BUS.getset_GRNMainDetails[0]["confaxno"]);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_CurrentConsigneeAddress"); 
            }
            return bolStatus;
        }

        public bool set_NewConsigneeAddress()
        {
            bool bolStatus = false;
            try
            {
                settfCargoRec.conid = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["comid"]);
                settfCargoRec.conline1 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline1"]);
                settfCargoRec.conline2 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline2"]);
                settfCargoRec.conline3 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline3"]);
                settfCargoRec.conline4 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline4"]);

                settfCargoRec.conareacode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["areacode"]);
                settfCargoRec.concitycode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["citycode"]);
                settfCargoRec.conpostcode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["poscode"]);
                 settfCargoRec.constatecode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["stacode"]);

                settfCargoRec.contelno = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["telno"]);
                settfCargoRec.contelpre = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["telpre"]);
                settfCargoRec.confaxpre = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["faxpre"]);
                settfCargoRec.confaxno = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["faxno"]);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ""); 
            }
            return bolStatus;
        }

        private bool set_NewShipperAddress()
        {
            bool bolStatus = false;
            try
            {
                //"SELECT comid, comregno, comname, addline1, addline2, addline3, addline4, areacode, " +
                //        "citycode, stacode, poscode, coucode, contact, " +
                //        "telpre, telno, faxpre, faxno, conope " +

                

                settfCargoRec.shipid = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["comid"]);
                settfCargoRec.shipline1 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline1"]);
                settfCargoRec.shipline2 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline2"]);
                settfCargoRec.shipline3 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline3"]);
                settfCargoRec.shipline4 = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["addline4"]);
                settfCargoRec.shipareacode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["areacode"]);
                settfCargoRec.shipcitycode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["citycode"]);
                settfCargoRec.shippostcode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["poscode"]);
                settfCargoRec.shipstatecode = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["stacode"]);
                settfCargoRec.shiptelno = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["telno"]);
                settfCargoRec.shiptelpre = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["telpre"]);
                settfCargoRec.shipfaxpre = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["faxpre"]);
                settfCargoRec.shipfaxno = clsGenFunction.get_checkStringNull(_BUS.get_ShipperAddress[0]["faxno"]);
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ShipperAddress"); 
            }
            return bolStatus;
        }
    }
}
